home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16786 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: svnews.ubinet.ubs.com!ubszh!ian.johnston@ubs.com
  2. From: ian.johnston@ubs.com (Ian Johnston (by ubsswop))
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Copy constructor
  5. Date: 12 Apr 1996 09:13:16 GMT
  6. Organization: UBS
  7. Distribution: world
  8. Message-ID: <4kl6rc$bpm@ubszh.fh.zh.ubs.com>
  9. References: <4kjudi$2qj0@holly.ACNS.ColoState.EDU>
  10. NNTP-Posting-Host: nol2179.fh.zh.ubs.com
  11.  
  12. In article <4kjudi$2qj0@holly.ACNS.ColoState.EDU>, corbyh@holly.ACNS.ColoState.EDU (Corby S. Hudnall) writes:
  13. |> Hi all, I'm having some trouble figuring out how to do a copy 
  14. |> constructor.  Here's what I thought was suppose to work:
  15. |> 
  16. |> header file----
  17. |> class ABC
  18. |> {
  19. |>     private:
  20. |>         int AnInt;
  21. |> 
  22. |>     public:
  23. |>         ABC():AnInt(5) {}  // Default Constructor
  24. |>         ~ABC() {}          // Default Destructor
  25. |>         ABC(const ABC&);   // Copy constructor
  26. |> }
  27. |> 
  28. |> ABC::ABC(const ABC& NewABC)
  29. |> {
  30. |>    this->AnInt = NewABC->AnInt;
  31. |> }
  32. |> 
  33. |> Unfortunatly, I can't get this to work right.  I get weird messages from 
  34. |> the compiler complaining about not being able to use a class definition 
  35. |> as an argument.  This was using xlC under IBM Aix.  Any suggestions are 
  36. |> greatly appreciated.  Thanks.
  37.  
  38.  
  39. Try:
  40.  
  41.     ABC::ABC(const ABC& NewABC)
  42.     {
  43.         this->AnInt = NewABC.AnInt;
  44.     }
  45.  
  46.  
  47. (The "this->" part is optional.)
  48.  
  49. Ian
  50.  
  51.